import java.io.IOException;
import java.net.InetSocketAddress;

import org.json.JSONException;
import org.json.JSONObject;

import light.im.IMEndpoint;
import light.im.IResponseHandler;
import light.im.logicserver.LogicServer;
import light.im.loginserver.LoginServer;
import light.network.Endpoint;
import light.network.EndpointHandlerAdapter;
import light.network.EndpointSession;
import light.network.PackProtocal;
import light.network.Packet;
import light.network.SendHandlerAdapter;
import light.network.UdpEndpoint;
import light.network.object.PackObject;


public class Run {

	public static void main(String[] args) throws Exception {
		
		new LoginServer();
		//new LogicServer();
		
		runClient();
	}
	
	static void runClient() throws Exception
	{
		JSONObject obj = new JSONObject().put("user", "haha").put("action", "login").put("psw", "haha");

		PackObject dat = new PackObject(obj);

		IMEndpoint client = new IMEndpoint("localhost", 10607);
		client.start();
		client.request(new InetSocketAddress("localhost", 10606), dat, new IResponseHandler() {
			@Override
			public void onSuccess(PackObject resp) {
				System.out.println("get resp: "+resp.getHeader());
			}
			@Override
			public void onFail(Throwable t) {
				t.printStackTrace();
			}
		});
	}
}
